﻿using Castle.Core.Logging;
using Castle.MicroKernel.Registration;
using System.Reflection;

namespace Inovout.Business
{
    public class BusinessComponentRegistrar : ComponentRegistrar
    {
        public override void Register()
        {
            Container.Register(
               Component.For<FunctionGroup>()
           );
        }
        public override void Register(Assembly assembly)
        {
            Container.Register(
                AllTypes.FromAssembly(assembly)
                .BasedOn<FunctionGroup>()
            );

            Container.Register(
                AllTypes.FromAssembly(assembly)
                .BasedOn<BaseWorkItem>()
                .WithService.Self()
                .WithService.AllInterfaces()
                .Configure(delegate(ComponentRegistration component)
                           {
                           component.LifeStyle.Transient
                               .OnCreate((instance) =>
                               {
                                   BaseWorkItem workItem = instance as BaseWorkItem;
                                   workItem.logger = Container.Resolve<IExtendedLogger>();
                                   workItem.viewData = Container.Resolve<IViewDataDictionary>();
                                   workItem.guiAction = Container.Resolve<IGuiAction>();
                               });
                       }
                   )
             );
        }
    }
}
